using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using Entities;
using Utility;
public partial class User_SanPhamTheoLoai : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
           LoadData_loai();
        }
    }


    private void LoadData_loai()
    {
        int id = int.Parse(Request.QueryString["id"].ToString());
       
        Pager.PageSize = 5;
        Criteria c = new Criteria();
        int total = 0;
        c.add(Condition.AND, tbSanPhamEntities.tbSanPhanEntitiesColumns.MaLoai.ToString(), Condition.EQUAL, int.Parse(id.ToString()));
       // c.add(Condition.AND, tbSanPham.tbSanPhamColumns.IDL.ToString(), Condition.EQUAL, int.Parse(Request.QueryString ["id"]));
        tbSanPhamEntities.tbSanPhanEntitiesCollection dd_Collection =tbSanPhamBUS.Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
           tbSanPhamEntities.tbSanPhanEntitiesColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater2.DataSource = dd_Collection;
        Repeater2.DataBind();
        Pager.ItemCount = total;
        if (total <= Pager.PageSize)
            Pager.Visible = false;
    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData_loai();
    }
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbSanPhamEntities sp = (tbSanPhamEntities)e.Item.DataItem;
            HyperLink hyp_sp = (HyperLink)e.Item.FindControl("hyp_sp");
            Literal lit_idsp = (Literal)e.Item.FindControl("lit_idsp");
            Image img_hinhanh = (Image)e.Item.FindControl("img_hinhanh");
            Literal lit_mota = (Literal)e.Item.FindControl("lit_mota");

            hyp_sp.Text = sp.TenSP;
            lit_idsp.Text = sp.MaSP.ToString();
            //lit_mota.Text = sp.MoTa.Substring(0, 40) + "...";


            int IDH = tbHinhAnhBUS.imageFirst(int.Parse(sp.MaSP.ToString()));
            tbHinhAnhEntities hh = tbHinhAnhBUS.GetByID(IDH);

            img_hinhanh.ImageUrl = "~/Photos/Thumb/" + hh.HinhAnh.ToString();
            //hyp_sp.NavigateUrl = "SanPhamCT.aspx?id= " + sp.IDSP.ToString();        
            HyperLink  btct = (HyperLink)e.Item.FindControl("btct");
            btct.NavigateUrl = "ChiTietSanPham.aspx?id= " + sp.MaSP.ToString(); 
        }

    }
}
